package net.facelib.sdk;

/**
 * 视频检测特性定义
 * @author guyadong
 *
 */
public class CaptureFeatures {
	/** 检测最大人脸 */
	public static final int DETECT_MAXFACE = 0x0001;
	/** 执行活体检测 */
	public static final int LIVENESS_FACE = 0x0002;
	/** 人脸检测图像顺时针旋转0度 */
	public static final int DETECT_ROTATE_0 = 0x0000;
	/** 人脸检测图像顺时针旋转90度 */
	public static final int DETECT_ROTATE_90 = 0x0010;
	/** 人脸检测图像顺时针旋转180度 */
	public static final int DETECT_ROTATE_180 = 0x0020;
	/** 人脸检测图像顺时针旋转270度 */
	public static final int DETECT_ROTATE_270 = 0x0030;
	/** 活体检测图像顺时针旋转0度 */
	public static final int LIVE_ROTATE_0 = 0x0000;
	/** 活体检测图像顺时针旋转90度 */
	public static final int LIVE_ROTATE_90 = 0x0040;
	/** 活体检测图像顺时针旋转180度 */
	public static final int LIVE_ROTATE_180 = 0x0080;
	/** 活体检测图像顺时针旋转270度 */
	public static final int LIVE_ROTATE_270 = 0x00C0;
	/** 人脸检测图像旋转角度掩码 */
	public static final int DETECT_ROTATE_MASK = 0x0030;
	
	/** 活体检测图像旋转角度掩码 */
	public static final int LIVE_ROTATE_MASK = 0x00C0;
	
	/** 执行特征提取 */
	public static final int FEATURE = 0x0100;
	/** 不执行执行识别 */
	public static final int RECOGNIZE_NONE = 0x0000;
	/** 执行1:1 识别 */
	public static final int RECOGNIZE_ONE = 0x0400;
	/** 执行1:1 识别 */
	public static final int RECOGNIZE_N = 0x0C00;	
	/** 识别掩码 */
	public static final int RECOGNIZE_MASK = 0x0C00;
	/** 默认特性定义 */
	public static final int DEFAULT_FEATURES = DETECT_MAXFACE  | DETECT_ROTATE_0 | LIVE_ROTATE_0;
	
	public static int getDetectRotate(int feature){
		switch (feature & DETECT_ROTATE_MASK) {
		case DETECT_ROTATE_0:
			return 0;
		case DETECT_ROTATE_90:
			return 90;
		case DETECT_ROTATE_180:
			return 180;
		case DETECT_ROTATE_270:
			return 270;
		default:
			throw new IllegalArgumentException();
		}
	}
	public static int getLiveRotate(int feature){
		switch (feature & LIVE_ROTATE_MASK) {
		case LIVE_ROTATE_0:
			return 0;
		case LIVE_ROTATE_90:
			return 90;
		case LIVE_ROTATE_180:
			return 180;
		case LIVE_ROTATE_270:
			return 270;
		default:
			throw new IllegalArgumentException();
		}
	}
	public static boolean isDetectMaxFace(int feature){
		return equalMask(feature ,DETECT_MAXFACE); 
	}
	public static boolean isLiveFace(int feature){
		return equalMask(feature, LIVENESS_FACE); 
	}

	public static boolean isExtractFeature(int feature){
		return equalMask(feature,FEATURE); 
	}
	public static boolean equalMask(int feature,int mask){
		return (feature & mask) == mask; 
	}
	/**
	 * 返回执行识别的模式
	 * <ul>
	 * <li>0x0000: 不识别</li>
	 * <li>0x0400: 1:1识别</li>
	 * <li>0x0C00: 1:N识别</li>
	 * </ul>
	 * @param feature
	 * @return 识别的模式
	 */
	public static int getRecognize(int feature){
		switch (feature & RECOGNIZE_MASK) {
		case RECOGNIZE_ONE:
			return RECOGNIZE_ONE;
		case RECOGNIZE_N:
			return RECOGNIZE_N;
		case RECOGNIZE_NONE:
			return RECOGNIZE_NONE;
		default:			
			throw new IllegalArgumentException(String.format("INVALID FEATURE 0x%x for recongize mode", feature & RECOGNIZE_MASK));
		}
	}
}
